/**
 * Copyright © 2016-2022 The Thingsboard Authors
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.thingsboard.server.common.data;


import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.JsonNode;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.thingsboard.server.common.data.id.IotConfigId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.validation.Length;
import org.thingsboard.server.common.data.validation.NoXss;

@Data
public class IotConfig extends SearchTextBasedWithAdditionalInfo<IotConfigId> implements HasName, HasTenantId {

    private static final long serialVersionUID = 245280192517613852L;

    @NoXss
    @Length(fieldName = "title")
    @ApiModelProperty(position = 3, value = "Title of the IotConfig", example = "title")
    private String title;

    @ApiModelProperty(position = 5, required = true, value = "JSON object with Tenant Id")
    private TenantId tenantId;

    public IotConfig() {
        super();
    }

    public IotConfig(IotConfigId id) {
        super(id);
    }

    public IotConfig(IotConfig iotConfig) {
        super(iotConfig);
        this.tenantId = iotConfig.getTenantId();
        this.title = iotConfig.getTitle();
    }

    @ApiModelProperty(position = 14, value = "Additional parameters of the iotConfig", dataType = "com.fasterxml.jackson.databind.JsonNode")
    @Override
    public JsonNode getAdditionalInfo() {
        return super.getAdditionalInfo();
    }

    @Override
    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    @ApiModelProperty(position = 4, value = "Name of the iotConfig. Read-only, duplicated from title for backward compatibility", example = "iotConfig", readOnly = true)
    public String getName() {
        return title;
    }

    @Override
    public String getSearchText() {
        return getTitle();
    }

}
